package com.gxa.admin.controller;


import com.gxa.common.vo.PageRecv;
import com.gxa.common.vo.R;
import com.gxa.common.vo.ResponseToken;
import com.gxa.common.vo.ResultVo;
import com.gxa.modules.pojo.Menu;
import com.gxa.modules.pojo.User;
import com.gxa.modules.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Api(value = "用户管理接口",tags = "（李晨）用户管理接口")
@RestController
@RequestMapping("/user")
public class UserController {


    @Autowired(required = false)
    UserService userService;


    @ApiOperation(value = "添加用户", notes = "添加用户", response = R.class)
    @PostMapping("/addUser")
    public ResultVo addUser(@RequestBody User user){
        ResultVo r=userService.addUser(user);
        return r;
    }

    @ApiOperation(value = "获取验证码", notes = "获取验证码", response = R.class)
    @PostMapping("/getCaptcha")
    public ResultVo getCaptcha(HttpServletRequest request){
        ResultVo r=userService.getCaptcha();
        return r;
    }

    @ApiOperation(value = "登录", notes = "登录", response = R.class)
    @PostMapping("/login")
    public ResponseToken login(@RequestBody User user,
                               @RequestParam String captchaKey,
                               @RequestParam String captchaValue,
                               HttpServletRequest request){
        ResponseToken r=userService.login(user,captchaKey,captchaValue,request);
        return r;
    }


    @ApiOperation(value = "通过条件获取用户（分页）", notes = "通过条件获取用户（分页）", response = R.class)
    @PostMapping("/getUserPageByCondition")
    public ResultVo getUserPageByCondition(@RequestBody PageRecv<User> userPageRecv){
        ResultVo r=userService.getUserPageByCondition(userPageRecv);
        return r;
    }

    @ApiOperation(value = "修改用户", notes = "修改用户", response = R.class)
    @PostMapping("/modifyUser")
    public ResultVo modifyUser(@RequestBody User user){
        ResultVo r=userService.modifyUser(user);
        return r;
    }

    @ApiOperation(value = "删除用户", notes = "删除用户", response = R.class)
    @PostMapping("/delUser")
    public ResultVo delUser(@RequestBody User user){
        ResultVo r=userService.delUser(user);
        return r;
    }

    @ApiOperation(value = "获取权限", notes = "获取权限", response = ResultVo.class)
    @PostMapping("/getPermission")
    public ResultVo getPermission(@RequestBody User user){
        ResultVo r=userService.getPermission(user);
        return r;
    }

    @ApiOperation(value = "退出登录", notes = "退出登录", response = ResultVo.class)
    @PostMapping("/logout")
    public ResultVo logout(@RequestBody User user){
        ResultVo r=userService.logout(user);
        return r;
    }



}
